package com.wwj.auction.login.controller;


import com.wwj.auction.common.result.R;
import com.wwj.auction.login.entity.vo.BuyRecordVo;
import com.wwj.auction.login.service.BuyRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wwj
 * @since 2021-08-31
 */
@RestController
@RequestMapping("/login/buyRecord")
@Api(tags = "购买记录")
public class BuyRecordController {

    @Autowired
    private BuyRecordService buyRecordService;

    /**
     * 查询买家的购买记录
     *
     * @param userId
     * @return
     */
    @ApiOperation("查询买家的购买记录")
    @GetMapping("/get/{userId}")
    public R get(@PathVariable("userId") @ApiParam("买家id") Integer userId) {
        List<BuyRecordVo> list = buyRecordService.get(userId);
        return R.ok().data("list", list);
    }

    /**
     * 确认收货
     *
     * @param id
     * @return
     */
    @GetMapping("/status/{id}")
    public R status(@PathVariable("id") Integer id) {
        buyRecordService.status(id);
        return R.ok().message("操作成功");
    }

    /**
     * 提供远程调用
     * 生成买家的购买记录
     *
     * @param userId
     * @param shopId
     * @return
     */
    @GetMapping("/create/{userId}/{shopId}/{orderNo}")
    public R create(
            @PathVariable("userId") Integer userId,
            @PathVariable("shopId") Integer shopId,
            @PathVariable("orderNo") String orderNo) {
        buyRecordService.create(userId, shopId, orderNo);
        return R.ok();
    }
}

